import { defineStore } from "pinia";

export const useNavStore = defineStore('nav', {
    state: () => {
        return {
            breadcrumbLevel: [] as RouteMeta[],
            // 新增状态，用于标记是否处于集群视图
            isClusterView: false,
            currentClusterId: '' as string,
            // 定义菜单项可见性,这里是初始化视图：如果有切换需要的话在后面的action进行切换
            menuVisibility: {
                // 默认导航项
                default: {
                    cluster: true,
                    micro: true,
                    reversesh: true,
                    ddos: true,
                    ztrust: true,
                    services: true,
                    security: true,
                    s3: true // 课题3界面
                },
                // 集群视图导航项
                cluster: {
                    overview: false,
                    resources: false,
                    monitoring: false,
                    events: false,
                    backToHome: false,
                    scheduling: false,
                }
            }
        }
    },
    actions: {
        // 切换到默认视图
        setDefaultView() {
            this.isClusterView = false;
            // 更新菜单可见性
            this.menuVisibility.default = {
                cluster: true,
                micro: true,
                reversesh: true,
                ddos: true,
                ztrust: true,
                services: true,
                security: true,
                s3: true // 课题3界面
            };
            this.menuVisibility.cluster = {
                overview: false,
                resources: false,
                monitoring: false,
                events: false,
                backToHome: false,
                scheduling: false,
            };
        },
        // 切换到集群视图
        setClusterView(clusterId) {
            this.isClusterView = true;
            // 更新菜单可见性
            this.menuVisibility.default = {
                cluster: false,
                micro: false,
                reversesh: false,
                ddos: false,
                ztrust: false
            };
            this.menuVisibility.cluster = {
                overview: true,
                resources: true,
                monitoring: true,
                events: true,
                backToHome: true,
                scheduling: true
            };
            this.currentClusterId = clusterId;
        }
    }
}
)

export interface RouteMeta {
    title: string
    value: string
    changeRoute: () => void  // 添加回调函数类型定义
}
